﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;

namespace Query
{
    class IndexContext : TableServiceContext
    {
        public IndexContext(string baseAddress,
            StorageCredentials credentials)
            : base(baseAddress, credentials)
        { 
        }

        public IQueryable<Index> index
        {
            get
            {
                return this.CreateQuery<Index>("index");
            }
        }

        public IQueryable<Index> Select(String partition, String term)
        {
            var results = from m in this.index where m.PartitionKey == partition && m.RowKey == term select m;
            return results;
        }

        public int getDocFreq(String term)
        {
            int docFreq = 0;
            var results = from m in this.index where m.RowKey == term select m;
            foreach (Index index in results)
            {
                docFreq += index.docFreq;
            }
            return docFreq;
        }
    }
}
